//
//  MovieShowViewController.m
//  UI_TabBarTest1(豆瓣)
//
//  Created by dllo on 16/6/25.
//  Copyright © 2016年 司昌宝. All rights reserved.
//

#import "MovieShowViewController.h"
#import "Movie.h"
#import "MovieShow.h"
#import "GetHeightTools.h"
#define kWidth self.view.frame.size.width
@interface MovieShowViewController ()

@property (nonatomic,retain)MovieShow *movieShow;

@end

@implementation MovieShowViewController

-(void)dealloc{
    [_movie release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self handleData];
    [self createButton];
    [self createView];
}
-(void)handleData{
    NSString *fileName = [NSString stringWithFormat:@"m%@",self.movie.movieId];
    NSString *path = [[NSBundle mainBundle]pathForResource:fileName ofType:@"txt"];
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    self.movieShow  = [[MovieShow alloc] init];
    [self.movieShow setValuesForKeysWithDictionary:[dictionary valueForKey:@"result"]];
    
}

-(void)createButton{
    self.title = self.movie.movieName;
    /** 返回按钮 */
    UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"btn_nav_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonItemAction:)];
    self.navigationItem.leftBarButtonItem = backButtonItem;
    /** 分享按钮 */
    UIBarButtonItem *shareButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"btn_nav_share"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonItemAction:)];
    self.navigationItem.rightBarButtonItem = shareButtonItem;
    
}

-(void)createView{
    UIImageView *postImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, kWidth * 0.3, 180)];
    NSURL *url = [NSURL URLWithString:self.movieShow.poster];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *image = [UIImage imageWithData:data];
    postImageView.image = image;
    [self.view addSubview:postImageView];
    [postImageView release];
    
    UILabel *ratingLabel = [[UILabel alloc] initWithFrame:CGRectMake(kWidth * 0.4, 20, kWidth * 0.6 - 20, 30)];
    ratingLabel.text = [NSString stringWithFormat:@"评分:  %@   (%@评论)",self.movieShow.rating,self.movieShow.rating_count];
    [self.view addSubview:ratingLabel];
    [ratingLabel release];
    
    UILabel *release_dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(kWidth * 0.4, 56, kWidth * 0.6 - 20, 30)];
    release_dateLabel.text = self.movieShow.release_date;
    [self.view addSubview:release_dateLabel];
    [release_dateLabel release];
    
    UILabel *runtimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(kWidth * 0.4, 92, kWidth * 0.6 - 20, 30)];
    runtimeLabel.text = self.movieShow.runtime;
    [self.view addSubview:runtimeLabel];
    [runtimeLabel release];
    
    UILabel *genresLabel = [[UILabel alloc] initWithFrame:CGRectMake(kWidth * 0.4, 128, kWidth * 0.6 - 20, 30)];
    genresLabel.text = self.movieShow.genres;
    [self.view addSubview:genresLabel];
    [genresLabel release];
    
    UILabel *film_loactionsLabel = [[UILabel alloc] initWithFrame:CGRectMake(kWidth * 0.4, 164, kWidth * 0.6 - 20, 30)];
    film_loactionsLabel.text = self.movieShow.film_locations;
    [self.view addSubview:film_loactionsLabel];
    [film_loactionsLabel release];
    
    UILabel *producer = [[UILabel alloc] initWithFrame:CGRectMake(20, 200, kWidth - 40, 80)];
    producer.text = @"制作人";
    producer.font = [UIFont systemFontOfSize:25.0];
    [self.view addSubview:producer];
    [producer release];
    
    UILabel *actorsLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 280, kWidth - 40, [GetHeightTools heightWith:self.movieShow.actors withWidth:kWidth - 40 withFontSize:17.0])];
    actorsLabel.text = self.movieShow.actors;
    actorsLabel.numberOfLines = 0;
    [self.view addSubview:actorsLabel];
    [actorsLabel release];
    
    UILabel *movieShowLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 280 + [GetHeightTools heightWith:self.movieShow.actors withWidth:kWidth - 40 withFontSize:17.0], kWidth - 40, 80)];
    movieShowLabel.text = @"电影介绍";
    movieShowLabel.font = [UIFont systemFontOfSize:25.0];
    [self.view addSubview:movieShowLabel];
    [movieShowLabel release];
    
    UILabel *plot_simpleLabel= [[UILabel alloc] initWithFrame:CGRectMake(20, 360 + [GetHeightTools heightWith:self.movieShow.actors withWidth:kWidth - 40 withFontSize:17.0], kWidth - 40, [GetHeightTools heightWith:self.movieShow.plot_simple withWidth:kWidth - 40 withFontSize:17.0])];
    plot_simpleLabel.text = self.movieShow.plot_simple;
    plot_simpleLabel.numberOfLines = 0;
    [self.view addSubview:plot_simpleLabel];
    [plot_simpleLabel release];
}



-(void)backButtonItemAction:(UIBarButtonItem *)backButtonItem{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)shareButtonItemAction:(UIBarButtonItem *)shareButtonItem{
    NSLog(@"点击了分享");
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
